import django_filters

from .models import *


class UserFilter(django_filters.rest_framework.FilterSet):
    """
    用户过滤的类
    """
    id_min = django_filters.NumberFilter(field_name='id', lookup_expr='gte')
    id_max = django_filters.NumberFilter(field_name='id', lookup_expr='lte')
    id_search = django_filters.CharFilter(field_name='id')
    username_search = django_filters.CharFilter(field_name='username', lookup_expr='icontains')
    sign_search = django_filters.CharFilter(field_name='sign', lookup_expr='icontains')
    nickname_search = django_filters.CharFilter(field_name='nickname', lookup_expr='icontains')
    gender_search = django_filters.CharFilter(field_name='gender')
    major_search = django_filters.CharFilter(field_name='major', lookup_expr='icontains')
    student_search = django_filters.CharFilter(field_name='student_id')
    ordering = django_filters.OrderingFilter(fields=('id', 'date_joined'),
                                             field_labels={'id': 'ID', 'date_joined': '添加时间'})

    class Meta:
        model = User
        fields = ['id_min', 'id_max']
